<template>
	<view>
		<view class="mainpadding ffffff">
			<view class="flexleft xiahuaxian margin_top">
				<view class="xiaohei sanshier fonweight kuandu minwidth">姓名</view>
				<input type="text" class="textright bfb" placeholder="请输入" v-model="name">
			</view>
			<view class="flexleft xiahuaxian margin_top" @click="show=true">
				<view class="xiaohei sanshier fonweight kuandu minwidth">证件类型</view>
				<view class="flexright bfb">
					<input type="text" class="textright margin_right2" placeholder="请选择证件类型" disabled=""
						v-model="idtype_name">
					<u-icon name="arrow-right" color="#999" size="18"></u-icon>
				</view>
			</view>
			<view class="flexleft xiahuaxian margin_top">
				<view class="xiaohei sanshier  fonweight kuandu minwidth">证件号码</view>
				<input type="text" class="textright bfb" placeholder="请输入" v-model="idcard">
			</view>
			<view class="flexbetween margin_top">
				<view class="xiaohei sanshier  fonweight kuandu minwidth">类型</view>
				<view class="flexright">
					<u-radio-group v-model="datatype" placement="row" circle>
						<u-radio activeColor="#2772f1" label="成人" :customStyle="{marginRight: '30rpx'}"
							:name="1"></u-radio>
						<u-radio activeColor="#2772f1" label="儿童" :name="2"></u-radio>
					</u-radio-group>
				</view>
			</view>
			<view class="xiaohui margin_top1 ershil">
				<text>{{passengers_typedes}}</text>
			</view>
			<view class="gudingdb ffffff mainpadding">
				<view class="bigbtn" @click="submit">保存</view>
			</view>
		</view>
		<view class="mainpadding xiaohui ershiba">
			<text>{{passengers_xy}}</text>
		</view>
		<u-picker :show="show" :columns="columns" keyName="name" @confirm="idcionfirm" @cancel="show=false"
			title="证件类型"></u-picker>
	</view>
</template>
<script>
	const httpRequest = require("@/common/httpRequest.js")

	export default {
		data() {
			return {
				listid: "",
				datatype: 1,
				name: "",
				idtype_id: "",
				idtype_name: "",
				idcard: "",
				show: false,
				columns: [],
				passengers_typedes:"",
				passengers_xy:"",
			}
		},
		onLoad(options) {
			if (options.id) {
				this.listid = options.id
				uni.setNavigationBarTitle({
					title: "编辑乘车人"
				})
				this.getDetail()
			}

			this.getidtypeIndex()
			this.getInfo()
		},
		methods: {
			getInfo(){
				httpRequest.request('/api/index/getConfigInfoItem','POST',{
					 pidtype:"about_set",
					 type:"passengers_typedes"
				}).then(res => {
					this.passengers_typedes = res.data
				})
				httpRequest.request('/api/index/getConfigInfoItem','POST',{
					 pidtype:"about_set",
					 type:"passengers_xy"
				}).then(res => {
					this.passengers_xy = res.data
				})
			},
			getDetail() {
				httpRequest.request('/api/user/passengersDetail', 'GET', {
					id:this.listid
				}).then(res => {
					let data = res.data
					this.name=data.name
					this.idtype_id=data.idtype.id
					this.idtype_name=data.idtype.name
					this.idcard=data.idcard
					this.datatype=Number(data.datatype)
				}).catch(err => {})
			},
			idcionfirm(e) {
				this.show = false
				this.idtype_id = e.value[0].id
				this.idtype_name = e.value[0].name
			},
			getidtypeIndex() {
				httpRequest.request('/api/user/idtypeIndex', 'GET', {}).then(res => {
					this.columns.push(res.data)
				}).catch(err => {})
			},
			submit() { //添加乘车人
				let _this = this
				if (this.name == '') {
					httpRequest.toast('请输入姓名');
					return false;
				}
				if (this.idtype_id == "") {
					httpRequest.toast('请输入选择证件类型');
					return false;
				}
				if (this.idcard == "") {
					httpRequest.toast('请输入证件号码');
					return false;
				}
				let data = {
					name: _this.name,
					idtype_id: _this.idtype_id,
					idcard: _this.idcard,
					datatype: _this.datatype,
				}
				let url = "/api/user/addPassengers"
				if (this.listid) {
					url = "/api/user/editPassengers"
					this.$set(data, "id", this.listid)
				}
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})
			},
		}
	}
</script>

<style>
	.bfb {
		width: 100%;
	}

	.minwidth {
		min-width: 150rpx;
	}
</style>